package Plugin_Reprise.editors.my_sql_editor;

import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.EndOfLineRule;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.IWordDetector;
import org.eclipse.jface.text.rules.MultiLineRule;
import org.eclipse.jface.text.rules.NumberRule;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.SingleLineRule;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;

public class EditorScanner extends RuleBasedScanner {
	
	
	public EditorScanner() { 
		super(); 
		setRules(extractRules()); 
		}   
	
	private static RGB KEYWORD= new RGB(140, 10, 210); 
	private static RGB KEYWORDCONST= new RGB(180, 180, 0); 
	private static RGB PREDICATERS= new RGB(20, 255, 20);
	private static RGB FUNCTIONS= new RGB(0, 0, 255); 
	private static RGB DEFAULT = new RGB(0,0,0);   
	private static RGB TEXT = new RGB(0,0,255);  
	private static RGB NUMBER = new RGB(255,0,0);  
	public static RGB COMMENT = new RGB(100, 180, 80);
	public static RGB COMMENTMASK = new RGB(215, 100, 100);
	public static RGB ALIAS = new RGB(208, 151, 45);  
	public static RGB TableUV = new RGB(0, 255, 0);  
	public static RGB SEPARATOR = new RGB(19, 168, 27);  
	private IRule[] extractRules() { 
		IToken keyword = new Token(new TextAttribute(new Color(Display.getCurrent(), KEYWORD), null, SWT.BOLD)); 
		IToken keywordconstants = new Token(new TextAttribute(new Color(Display.getCurrent(), KEYWORDCONST), null, SWT.BOLD)); 
		IToken functions = new Token(new TextAttribute(new Color(Display.getCurrent(), FUNCTIONS), null, SWT.BOLD | SWT.UNDERLINE_SINGLE)); 
		IToken predicates = new Token(new TextAttribute(new Color(Display.getCurrent(), PREDICATERS), null, SWT.BOLD)); 
		IToken defaut = new Token(new TextAttribute(new Color(Display.getCurrent(), DEFAULT)));   
		IToken texte =new Token(new TextAttribute(new Color(Display.getCurrent(), TEXT)));
		IToken nombres =new Token(new TextAttribute(new Color(Display.getCurrent(), NUMBER)));
		WordRule rule = new WordRule(new IWordDetector() { 
			@Override public boolean isWordPart(char c) { 
				return Character.isJavaIdentifierPart(c) ; 
				}   
			@Override public boolean isWordStart(char c) { 
				return Character.isJavaIdentifierStart(c) ; 
				} 
			}, defaut);   
		
		for (String k : KeyWords.getFunctions()) { 
			rule.addWord(k, functions); 
		}   
		for (String k : KeyWords.getReservedwords()) { 
			rule.addWord(k, keyword); 
		}   
		for (String k : KeyWords.getConstants()) { 
			rule.addWord(k, keywordconstants); 
		}  		
		for (String k : KeyWords.getPredicates()) { 
			rule.addWord(k, predicates); 
		}  		

		//IToken tag = new Token("__commenttag");

		
		IRule [] rules = new IRule[3]; 
		rules[0]=rule; 		
		rules[1]=new SingleLineRule("'", "'", texte); 
		rules[2]=new NumberRule(nombres); 


		

return rules; 
} 
}
